import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import React,{Component} from 'react';
import 'antd/dist/antd.css';
import '../Assets/Login.css';
import axios from 'axios';
import {withRouter } from 'react-router-dom'

class LoginForm extends React.Component{
    onFinish = (values) => {
        console.log('Received values of form: ', values);
        let history = this.props.history;
        axios.post('http://localhost:8080/author/login', values)
            .then(function (response) {
                console.log("response: ", response.data);
                if(response.data==="登录成功")
                    history.push('/mainpage');
                else
                    alert(response.data);
            })
            .catch(err => console.log(err))

    }

    render() {
        //const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
        return (
            <Form
                name="normal_login"
                className="login-form"
                initialValues={{
                    remember: true,
                }}
                onFinish={this.onFinish}
                //onSubmit={this.handleSubmit}
            >
                <Form.Item
                    name="email"
                    rules={[
                        {
                            required: true,
                            message: 'Please input your Email!',
                        },
                    ]}
                >
                    <Input prefix={<UserOutlined className="site-form-item-icon"/>} placeholder="Email"/>
                </Form.Item>
                <Form.Item
                    name="password"
                    rules={[
                        {
                            required: true,
                            message: 'Please input your Password!',
                        },
                    ]}
                >
                    <Input
                        prefix={<LockOutlined className="site-form-item-icon"/>}
                        type="password"
                        placeholder="Password"
                    />
                </Form.Item>
                <Form.Item>
                    <Form.Item name="remember" valuePropName="checked" noStyle>
                        <Checkbox>Remember me</Checkbox>
                    </Form.Item>

                    <a className="login-form-forgot" href="">
                        Forgot password
                    </a>
                </Form.Item>

                <Form.Item>
                    <Button type="primary" htmlType="submit" className="login-form-button">
                        Log in
                    </Button>
                    Or <a href="">register now!</a>
                </Form.Item>
            </Form>
        );
    }
}

//let Login = Form.create()(LoginForm);
export default withRouter(LoginForm);